package com.xinqi.modules.chat.chat.message.controller.app;

import com.xinqi.common.base.response.R;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.chat.chat.message.dto.req.ChatMessageCancelTopDTO;
import com.xinqi.modules.chat.chat.message.dto.req.ChatMessageTopDTO;
import com.xinqi.modules.chat.chat.message.dto.rsp.ChatTopMessageResultDTO;
import com.xinqi.modules.chat.chat.message.service.ChatTopMessageService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * APP -- 聊天消息置顶
 *
 * @author: yyzhen
 * @date: 2023/06/29
 */
@Validated
@RestController
@RequestMapping("/app/chat-top-message")
@RequiredArgsConstructor
public class ChatTopMessageAppController {
    private final ChatTopMessageService chatTopMessageService;

    @Operation(summary = "根据会话ID查询置顶消息")
    @GetMapping("/list-target/{targetId}")
    public R<List<ChatTopMessageResultDTO>> listByTargetId(@NotEmpty(message = "{chat.message.top.targetId.not.blank}") @PathVariable("targetId") String targetId) {
        return R.data(chatTopMessageService.listByTargetId(targetId));
    }

    @Operation(summary = "消息置顶")
    @PostMapping("/top")
    public R<Long> topMessage(@Validated @RequestBody ChatMessageTopDTO dto) {
        return R.data(chatTopMessageService.topMessage(dto, LoginHelper.getXqLoginUser()));
    }

    @Operation(summary = "取消置顶")
    @PostMapping("/cancel-top")
    public R<Boolean> cancelTop(@Validated @RequestBody ChatMessageCancelTopDTO dto) {
        return R.data(chatTopMessageService.cancelTopMessage(dto,LoginHelper.getXqLoginUser()));
    }

}
